<?php
header('Content-Type:application/json;charset=utf-8');
$raw=file_get_contents('php://input');
$raw=json_decode($raw,true);
$id=$raw['id'];
$name=$raw['name'];

if( !is_dir("科目") ){
    mkdir("科目");
}
if($id!='' && $name!=''){
    if( !file_exists("科目/$id") ){
        @$kmmc=file_get_contents("科目/$id");
        if( $name != $kmmc ){
            file_put_contents("科目/$id",$name);
            $arr=array('msg'=>'成功','content'=>'新建成功！');
            echo json_encode($arr,JSON_UNESCAPED_UNICODE);
        }else{
            $arr=array('msg'=>'失败','content'=>'该名称重复！');
            echo json_encode($arr,JSON_UNESCAPED_UNICODE);
        }
    }else{
        $arr=array('msg'=>'失败','content'=>'该ID已存在！');
        echo json_encode($arr,JSON_UNESCAPED_UNICODE);
    }
}else{
    $arr=array('msg'=>'失败','content'=>'参数不完整！');
    echo json_encode($arr,JSON_UNESCAPED_UNICODE);
}
